<?php
require 'settings.php';
require 'en.php';
if(!$set['run']) {
    echo $set['offtext'];
    exit();
};
define('ACT',$_GET['act']);
define('TID',$_GET['tid']);
define('ID',$_GET['id']);
define('P',$_GET['p']);
require 'model.php';
require 'channels.php';
if ($_GET['api'] && $set['api'] && $_GET['s'] == $set['apipwd']) {
    header('content-type:text/plain');
    if($_GET['::json']) {
        echo str_replace('\/','/',json_encode($ch,JSON_UNESCAPED_UNICODE));
    } else {
        print_r($ch);
    };
    exit();
};
if(ACT == 'list' && $ch[TID]) {
    $a = count($ch[TID]);
    $_ = str_replace('$KEYWORDS$',TID.'在線觀看,',htmlhead);
    $_ = str_replace('$DESCRIPTION$','在線觀看'.TID.'。',$_);
    $_ = str_replace('$TITLE$','頻道列表 - '.$set['title'],$_).'<center><b>共'.$a.'個頻道</b></center><div data-role="content"><ul data-role="listview" data-inset="true" data-divider-theme="a" data-filter="true" data-filter-placeholder="鍵入想看到的頻道">';
    echo $_;
    foreach($ch[TID] as $a => $b) {
        $lines = count($ch[TID][$a]['url']) - 1;
        if($ch[TID][$a]['icon'] == '') {
            $icon = $set['noimg'];
        } else {
            $icon = $ch[TID][$a]['icon'];
        };
        $qn = $ch[TID][$a]['qn'];
        if(!$ch[TID][$a]['unshow']) {
            echo '<li><a href="/?act=play&tid='.TID.'&id='.$a.'&p=0" data-inline="true" data-ajax="false"><img src="'.$icon.'" width="100%"></img>'.$a.'<hr color="'.$set['theme'].'"></hr><font color="green" size="1px">'.$qn.'</font></a></li>';
        };
    };
    echo '</ul></div>'.htmlfoot;
} else if(ACT == 'play' && $ch[TID][ID]['url'][P]) {
    $epgid = $ch[TID][ID]['epgid'];
    if(preg_match('/Windows|Macintosh;|iPad;/',$_SERVER['HTTP_USER_AGENT'])) {
        $height = '800px';
    } else {
        $height = '216';
    };
    $a = P + 1;
    $_ = str_replace('$KEYWORDS$',ID.'在線觀看,',htmlhead);
    $_ = str_replace('$DESCRIPTION$','在線觀看'.ID.'。',$_);
    $_ = str_replace('$TITLE$',$_GET['id'].' - '.$set['title'],$_).'<div data-role="content"><div align="center">'.$set['headtext'].'</div><center style="background-image: linear-gradient(to right, #004680, #66ffcc);"><font color="White">线路'.$a.'|'.ID.'</font></center><script>var str=de("'.en(urlencode(GeJISafe(TID.'&'.ID.'&'.P.'&'.time())),'').'").replace(/'.en('','M').'/g,\'M\');var url=atob(str);document.write(\'<iframe allowfullscreen="allowfullscreen" mozallowfullscreen="mozallowfullscreen" msallowfullscreen="msallowfullscreen" oallowfullscreen="oallowfullscreen" webkitallowfullscreen="webkitallowfullscreen" width="100%" height="'.$height.'" src="/player.php?s=\' + url + \'"></iframe>\');</script><ul data-role="listview" data-inset="true" data-divider-theme="a"><li data-role="list-divider"><font color="red" class="blink">●</font> LIVE 直播中</li>';
    echo $_;
    for($i = 0; $i <= count($ch[TID][ID]['url']) - 1; $i++) {
        $b = $i + 1;
        echo '<li><a href="/?act=play&tid='.TID.'&id='.ID.'&p='.$i.'" data-inline="true" data-ajax="false">线路'.$b.'&nbsp&nbsp&nbsp&nbsp'.$ch[TID][ID]['url'][$i][0].'</a></li>';
    };
    $_ = '<li data-role="list-divider">頻道介紹</br>'.$ch[TID][ID]['desc'].'</li><li data-role="list-divider">'.ID.' '.date('Y-m-d').' 節目預告</li><div align="center"></div>'.@file_get_contents('http://'.$_SERVER['HTTP_HOST'].'/epg.php?id='.urlencode(ID)).'</div>'.htmlfoot;
    echo $_;
} else {
    $_ = str_replace('$TITLE$',$set['title'].' - '.$set['title2'],htmlhead);
    if(!preg_match('/Windows|Macintosh;|iPad;/',$_SERVER['HTTP_USER_AGENT'])) {
        $a = '<img src="'.$set['topicon'].'" width="100%"></img>';
    };
    echo $_.$a.'<div data-role="content"><div align="center">'.$set['hometext'].'</div><ul data-role="listview" data-inset="true" data-divider-theme="a">';
    foreach($ch as $a => $b) {
       echo '<li><a href="/?act=list&tid='.$a.'"data-ajax="false">'.$a.'</a></li>';
   };
    echo '</ul></div>'.htmlfoot;
};